package com.walle.netty;

import java.util.concurrent.CountDownLatch;

/**
 * @author zhangjiapeng
 * @Package com.walle.netty
 * @Description: ${todo}
 * @date 2019/1/22 16:46
 */
public class TTC {

    private static int h = 60400;
    private static int w = 1010;
    private static int countPerGroup = 10000;
    private static CountDownLatch _latch;

    public static void main(String[] args) throws InterruptedException {

        int[][] arr = new int[h][w];
        int groupCount = h%countPerGroup == 0 ? h/countPerGroup: h/countPerGroup + 1;
        _latch = new CountDownLatch(groupCount);
        int value = 0;
        Long startTime = System.currentTimeMillis();
        for(int i=0;i<h;i = i + countPerGroup){
            int start = i;
            int end = i+countPerGroup > 60400? 60400:i+countPerGroup;
            value = i*1010;
            new Thread(new TTCHandle(start,end,value,arr,_latch)).start();
        }
        _latch.await();
        System.out.println("多线程耗时："+ (System.currentTimeMillis()-startTime) +"ms");
    }

}

class TTCHandle implements Runnable{

    private CountDownLatch _latch;
    private int start;
    private int end;
    private int value;
    private int[][] arr;
    public TTCHandle(int start, int end, int value,int[][] arr,CountDownLatch _latch) {
        this.start = start;
        this.end = end;
        this.value = value;
        this.arr = arr;
        this._latch = _latch;
    }

    @Override
    public void run() {
        for(int i=start;i<end;i++){
            for (int j=0;j<1010;j++){
                arr[i][j] = value;
                value++;
            }
        }
        _latch.countDown();
    }
}
